-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure all signatures returned by beforeSign hooks are valid #25
base: v0.3.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To spark a discussion on these changes before I implement them - this change is intended to catch situations where multiple plugins implement beforeSign
hooks that mutate and sign the transaction.
Given a Session
with 2x plugins, both which mutate and sign:
- Plugin 1 mutates and prepends an action, then signs. The transaction has X+1 actions.
- Plugin 2 mutates and prepends an action, then signs. The transaction has X+2 actions now.
The signature from Plugin 1 is now invalid, since Plugin 2 mutated the transaction.
@@ -62,6 +63,7 @@ export interface SessionOptions { | |||
permissionLevel: PermissionLevelType | string | |||
transactPlugins?: AbstractTransactPlugin[] | |||
transactPluginsOptions?: TransactPluginsOptions | |||
validatePluginSignatures?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an option to turn on and off this functionality.
@@ -198,6 +204,7 @@ export class Session { | |||
// Create response template to this transact call | |||
const result: TransactResult = { | |||
chain: this.chain, | |||
keys: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store an array of all the public keys used to sign the request to provide in the response and for use during signature validation after the beforeSign
hooks complete.
}) | ||
|
||
// Merge newly discovered keys into the TransactResult. | ||
result.keys = [...result.keys, ...recoveredKeys] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When signatures are returned by beforeSign
hooks, recover the public key from the signature using the current digest of the transaction.
} | ||
} | ||
|
||
// Validate all the signatures returned by the plugins against the current request | ||
if (willValidatePluginSignatures) { | ||
this.validateBeforeSignSignatures(context, request, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the transaction is finalized (after all beforeSign
hooks), and before the wallet signs the transaction, validate all of the signatures provided against the transaction the user is about to sign.
This will throw an error if any of the signatures provided by the plugins are invalid (since the transaction would fail upon broadcast anyways).
) | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method takes the current request and all public keys recovered from the signatures provided by the beforeSign
hooks. It recovers the digest from the transaction, and then for each signature, ensures that the signature is valid for the digest and the key recovered from the current digest/signature combo matches what was originally used.
This can be disabled with the `validatePluginSignatures` option, it is enabled by default to ensure that multiple mutations in the `beforeSign` hooks don't invalidate any signatures they may create.
e3bd626
to
48b0fdb
Compare
This can be disabled with the
validatePluginSignatures
option, it is enabled by default to ensure that multiple mutations in thebeforeSign
hooks don't invalidate any signatures they may create.